struct VertIn
{
	float4 pos		: POSITION;
	float4 inNormal	: NORMAL;
	float2 texcoord	: TEXCOORD0;

};

struct VertOut
{
	float4 pos		: Position;
	float2 texcoord	: TEXCOORD0;
	float3 eyeDir	: TEXCOORD1;
	float3 outNormal: TEXCOORD2;
	float4 colour	: COLOR
};

// Vertex Shader
VertIn mainVS(	VertIn input,
				uniform float4x4 worldViewProjMat
				uniform float3 eyePos // object space
				)
{
	// Initialise output with zero's
	VertOut output	= (VertOut)0;
	
	// World View Projection Matrix - OGRE is MATRIX by POS
	output.pos		= mul(worldViewProjMat, input.pos);

	// Calcuate Texture Coords
	output.texcoord	= input.texcoord;
	
	output.eyeDir	= normalize(input.pos - eyePos);
	// Calculate normal
	output.outNormal= input.inNormal;

	return output;
}

// Fragment Shader
float4 mainPS(	VertOut input,
				uniform float fresnelBias,
				uniform float fresnelScale,
				uniform float fresnelPower,
				uniform sampler2D img : register(s0),
				uniform sampler2D reflectMap : register(s1)) : COLOR0
{
	float4 myTex 	= tex2D(img, input.texcoord);
	// fresnel
	float fresnel	= fresnelBias + fresnelScale * pow(1 + dot(eyeDir, outNormal), fresnelPower);
	// reflection
	float4 reflectionColour	= tex2D(reflectMap, myTex);
	// final output
	colour = lerp(reflectionColour, fresnel);
	
//	return myTex;
}